package com.compass.doctor.ui.patient.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.compass.doctor.databinding.LayoutAppendTagItemBinding
import com.compass.doctor.databinding.LayoutUsefulExpressionsItemBinding
import com.compass.framework.adapter.BaseBindViewHolder
import com.compass.framework.adapter.BaseMultiItemAdapter
import com.compass.framework.ext.saveAs
import com.compass.framework.model.Tag

/**
 * Description： 添加标签item
 * Date:2023/12/14 15:52
 */
class AppendTagAdapter  (private var itemType: Int) :
    BaseMultiItemAdapter<Tag>() {


    //用来实现多item布局
    override fun getDefItemViewType(position: Int): Int {
        return itemType
    }

    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<ViewBinding>,
        item: Tag?,
        position: Int
    ) {
        if (item == null) return
        //  1、标签item 2、常用语item
        when (holder.itemViewType) {
            1 -> {
                val binding = holder.binding.saveAs<LayoutAppendTagItemBinding>()
                binding.actionText.text = item.title

            }

            else -> {
                val binding = holder.binding.saveAs<LayoutUsefulExpressionsItemBinding>()
                binding.actionText.text = item.title
            }
        }


    }

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ViewBinding {
        return when (viewType) {
            1 -> {
                LayoutAppendTagItemBinding.inflate(layoutInflater, parent, false)
            }
            else -> {
                LayoutUsefulExpressionsItemBinding.inflate(layoutInflater, parent, false)
            }
        }

    }
}